#include <iostream>

using namespace std;

const int N = 2e5 + 10;
typedef long long LL;

LL n;
LL a[N];

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];

	//一旦sum为负数，就舍弃
	LL ret = -1e6;
	LL sum = 0;
	for(int i = 1; i <= n; i++)
	{
		sum += a[i];
		ret = max(ret, sum);
		if(sum < 0) sum = 0;
	}
	cout << ret << endl;

	return 0;
}


